home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / bipl.zip / PROGS.ZIP / CSTRINGS.ICN < prev    next >
Text File  |  1992-11-26  |  2KB  |  90 lines

  1. ############################################################################
  2. #
  3. #    File:     cstrings.icn
  4. #
  5. #    Subject:  Program to print strings in C files
  6. #
  7. #    Author:   Robert J. Alexander
  8. #
  9. #    Date:     September 17, 1990
  10. #
  11. ###########################################################################
  12. #
  13. #  Program to print all strings (enclosed in double quotes) in C source
  14. #  files.
  15. #
  16.  
  17. procedure main(arg)
  18.    local c,f,fn,line,lineNbr,s
  19.    if *arg = 0 then stop("Usage: cstrings file...")
  20.    every fn := !arg do {
  21.       f := open(fn) | stop("Can't open \"",fn,"\"")
  22.       lineNbr := 0
  23.       while line := read(f) do line ? {
  24.      lineNbr +:= 1
  25.      while tab(upto('/"\'')) do {
  26.         case move(1) of {
  27.            #
  28.            #  Comment -- handled because it could contain something that
  29.            #  looks like a string.
  30.            #
  31.            "/": {
  32.           if ="*" then {
  33.              while not tab(find("*/") + 2) do {
  34.             &subject := read(f) | stop("Unexpected EOF in comment")
  35.             lineNbr +:= 1
  36.             }
  37.              }
  38.           }
  39.            #
  40.            #  String
  41.            #
  42.            "\"": {
  43.           s := "\""
  44.           while s ||:= tab(upto('"\\')) do {
  45.              s ||:= c := move(1)
  46.              case c of {
  47.             "\\": {
  48.                if not (s ||:= move(1)) then {
  49.                   s[-1] := ""
  50.                   &subject := read(f) |
  51.                     stop("Unexpected EOF in string")
  52.                   lineNbr +:= 1
  53.                   }
  54.                }
  55.             "\"": {
  56.                break
  57.                }
  58.             }
  59.              }
  60.           write("+",lineNbr," ",fn," ",s)
  61.           }
  62.            #
  63.            #  Character constant -- handled because it might contain
  64.            #  a double quote, which could be mistaken for the start
  65.            #  of a string.
  66.            #
  67.            "'": {
  68.           while tab(upto('\'\\')) do {
  69.              c := move(1)
  70.              case c of {
  71.             "\\": {
  72.                if not move(1) then {
  73.                   &subject := read(f) |
  74.                     stop("Unexpected EOF in character constant")
  75.                   lineNbr +:= 1
  76.                   }
  77.                }
  78.             "'": {
  79.                break
  80.                }
  81.             }
  82.              }
  83.           }
  84.            }
  85.         }
  86.      }
  87.       close(f)
  88.       }
  89. end
  90.